<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{width:100px;height:200px;background: #ccc;display: none;position: absolute;left:0;top:0;}
    </style>
</head>
<body>
    <div class="box">
        这是右键菜单
    </div>
</body>
<script>

    var oBox = document.querySelector(".box")

    document.oncontextmenu = function(eve){
        var e = eve || window.event;
        // 阻止默认事件
        // IE低版本：e.returnValue = false;
        // 正常：e.preventDefault();
        stopDefault( e );

        // 显示自定义右键菜单
        oBox.style.display = "block";
        oBox.style.left = e.pageX + "px";
        oBox.style.top = e.pageY + "px";
    }

    document.onclick = function(){
        oBox.style.display = "none";
    }

    function stopDefault(e){
        if(e.preventDefault){
            e.preventDefault()
        }else{
            e.returnValue = false;
        }
    }
</script>
</html>